package cn.edu.cqie.maven_onlinexem.controller;

import cn.edu.cqie.maven_onlinexem.bean.AjaxResult;
import cn.edu.cqie.maven_onlinexem.bean.Student;
import cn.edu.cqie.maven_onlinexem.bean.admin;
import cn.edu.cqie.maven_onlinexem.service.AdminService;
import cn.edu.cqie.maven_onlinexem.until.MD5;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class AdminController {
    @Resource
    AdminService adminService;
    @RequestMapping("admin_login")
    public ModelAndView admin_login(){
        ModelAndView modelAndView = new ModelAndView("admin_login");
        return modelAndView;
    }
    @RequestMapping("admin_select")
    public ModelAndView admin_select(){
        ModelAndView modelAndView = new ModelAndView("admin_select");
        return modelAndView;
    }
    @ResponseBody
    @RequestMapping("doAjaxAdmin_Login")
    public Object doAjaxAdmin_Login(admin admin, HttpSession session, HttpServletResponse response){
        String passwordMD5 = MD5.MD5(admin.getAdmin_password());
        admin.setAdmin_password(passwordMD5);
        boolean b = adminService.admin_login(admin);
        AjaxResult ajaxResult = new AjaxResult();
        if(b){
            session.setAttribute("loginAdmin",admin.getAdmin_name());
            ajaxResult.setSuccess(true);
        }
        else {
            ajaxResult.setSuccess(false);
        }
        System.out.println(ajaxResult);
        return ajaxResult;
    }
}
